package xdu.lz.stage3_classloader.chapter3;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public final class EncryptUtils {

    public static final byte ENCRYPT_FACTOR = (byte) 0xff;

    private EncryptUtils(){
        //empty
    }

    public static void doEncrypt(String source, String des){
        try(FileInputStream in = new FileInputStream(source);
            FileOutputStream out = new FileOutputStream(des)){
            int data;
            while ((data = in.read()) != -1){
                out.write(data^ENCRYPT_FACTOR);
            }
        }catch (IOException e){
            e.printStackTrace();
            return;
        }
    }
    //解码就是再次编码，对称加密
    public static void doDecrypt(String source,String des){
        doEncrypt(source,des);
    }

    public static void main(String[] args) {
        EncryptUtils.doEncrypt("F:\\IDEA\\IDEA\\workspace\\multi-threaded-concurrency" +
                        "\\myclassloader3\\xdu\\lz\\stage3_classloader\\chapter3\\TestObj.class",
                "F:\\IDEA\\IDEA\\workspace\\multi-threaded-concurrency" +
                        "\\myclassloader3\\xdu\\lz\\stage3_classloader\\chapter3\\TestObj1.class");
    }
}
